package org.xg.study.pd;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName LoginSSODecorator
 * @date 2021/9/15 13:37
 **/
public class LoginSSODecorator extends SSOInterceptor {
    private static Map<String, String> authMap = new ConcurrentHashMap<>();

    static {
        authMap.put("huahua", "queryUserInfo");
        authMap.put("doudou", "queryUserInfo");
    }

    @Override
    public boolean preHandle(String request, String response, Object handler) {
        //模拟获取cookie
        String ticket = request.substring(1, 8);
        //模拟校验
        boolean success = ticket.equals("success");
        if (!success) {
            return false;
        }
        String userId = request.substring(9);
        String method = authMap.get(userId);
        //模拟方法校验
        return "queryInfo".equals(method);
    }
}
